<template>
  <el-form :inline="true" :model="queryParam" class="demo-form-inline">
    <el-form-item label="用户名:">
      <el-input v-model="queryParam.userName" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="昵称:">
      <el-input v-model="queryParam.nickName" placeholder="昵称"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">查询</el-button>
    </el-form-item>
  </el-form>

  <el-table ref="tableRef" row-key="date" :data="tableData" style="width: 100%">
    <el-table-column prop="userName" label="用户名" width="180" />
    <el-table-column prop="nickName" label="昵称" width="180" />
    <el-table-column prop="email" label="邮箱" />
  </el-table>
  <el-pagination
    style="margin-top: 20px"
    background
    layout="prev, pager, next, total"
    :total="total"
    @current-change="changePage"
    :page-sizes="[2, 5, 10.15]"
    :page-size="queryParam.size"
  />
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { listUser } from '@/api/user'

const tableRef = ref()

const queryParam = ref({
  size: 2,
  page: 0,
  userName: '',
  nickName: ''
})
const total = ref(0)
const tableData = ref([])

const getListUser = async () => {
  const res = await listUser(queryParam.value)
  tableData.value = res.data.content
  total.value = res.data.totalElements
  queryParam.value.size = res.data.size
}

onMounted(() => {
  getListUser()
})

const changePage = (current) => {
  queryParam.value.page = current - 1 //下标从0开始
  getListUser()
}

const onSubmit = () => {
  getListUser()
  queryParam.value.page = 0
}
</script>

<style></style>
